// pages/homepage/homepage/homepage.js
const app = getApp();
const Request = require('../../../../utils/request.js');

Page({

  /**
   * 页面的初始数据
   */
  data: {

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    
  },

  loadData: function() {
    var that = this;
    console.log(that);
    Request.createAll([
      app.server.getConnect({
        point_url: app.server.adminApi.getGlobalData,
        admin_id: app.globalData.userInfo.id
      }),
      app.server.getConnect({
        point_url: app.server.adminApi.getTodayCustomer,
        admin_id: app.globalData.userInfo.id
      }),
      app.server.getConnect({
        point_url: app.server.adminApi.getRankingList,
      }),
      app.server.getConnect({
        point_url: app.server.adminApi.getNews,
      })
    ]).then(function(res) {
      console.log(res);
      that.setData({
        globalData1: res[0].data,
        globalData2: res[1].data,
        dataList: res[2].data.slice(0, 3),
        newsTitle: res[3].data.title
      });
    })
  },

  toRankingList: function() {
    wx.navigateTo({
      url: '/pages/admin/homepage/ranking-list/ranking-list',
    })
  },

  toNews:function(){
    wx.navigateTo({
      url: '/pages/admin/homepage/news/news',
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {
    app.pageOnloadInit(this, app);
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    var userInfo = wx.getStorageSync('userInfo');
    app.globalData.userInfo = userInfo;
    console.log(userInfo);
    if (wx.getStorageSync('openid')) {
      this.loadData();
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    // 初始化小程序样式
    app.utils.initAdminWxappStyle(app, this);
    wx.stopPullDownRefresh();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})
